const sass = require('sass')
const loadGruntTasks = require('load-grunt-tasks')
module.exports = grunt => {
  grunt.initConfig({
    //清除指定路径下的文件，这个clean由插件自动载入
    // clean: {
    //   temp: 'temp/app.js'
    // },
    sass: {
      main: {
        options: {
          implementation: sass
        },
        files: {
          'dist/css/main.css': 'src/scss/main.scss'
        }
      }
    },
    babel: {
      main: {
        options: {
          presets: ['@babel/preset-env']
        },
        files: {
          'dist/js/main.js': 'src/js/main.js'
        }
      }
    },
    watch: {
      js: {
        files: ['src/js/main.js'],
        tasks: ['babel']
      },
      css: {
        files: ['src/scss/main.scss'],
        tasks: ['sass']
      }
    }
  })

  //自动加载所有grunt插件
  loadGruntTasks(grunt)
  //loadNpmTasks 加载插件
  // grunt.loadNpmTasks('grunt-sass')
  // grunt.loadNpmTasks('grunt-babel')

  grunt.registerTask('default', ['sass', 'babel', 'watch'])

}